package com.xinhe.web.util;

public class CharCodeUtil {
    private static final String LETTER_LOWER = "abcdefghijklmnopqrstuvwxyz";
    private static final String LETTER_UPPER = "abcdefghijklmnopqrstuvwxyz".toUpperCase();
    private static final String DIGITAL = "1234567890";
    private static final String CHAR = "abcdefghijklmnopqrstuvwxyz1234567890" + LETTER_UPPER;

    public static String generateRandomCode(String codeChar, int length) {
        StringBuilder code = new StringBuilder();
        Random random = new Random();
        for (int i = 0; i < length; i++) {
            code.append(codeChar.charAt(random.nextInt(codeChar.length())));
        }
        return code.toString();
    }

    public static String generateLowerLetterRandomCode(int length) {
        return generateRandomCode("abcdefghijklmnopqrstuvwxyz", length);
    }

    public static String generateUpperLetterRandomCode(int length) {
        return generateRandomCode(LETTER_UPPER, length);
    }

    public static String generateDigitalRandomCode(int length) {
        return generateRandomCode("1234567890", length);
    }

    public static String generateCharRandomCode(int length) {
        return generateRandomCode(CHAR, length);
    }
}
